package com.longmao.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.longmao.commonutils.R;
import com.longmao.eduservice.entity.EduCourse;
import com.longmao.eduservice.entity.EduTeacher;
import com.longmao.eduservice.service.EduCourseService;
import com.longmao.eduservice.service.EduTeacherService;
import com.longmao.servicebase.handler.LongMaoException;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;
import java.util.Map;

/**
 * @author longmao
 * @date 2022/2/22 17:46
 * Content:  前台讲师
 */
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    /**
     * 分页查询讲师的方法
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("/pageTeacherList/{page}/{limit}")
    public R pageTeacherList(@PathVariable long page, @PathVariable long limit) {

        Page<EduTeacher> teacherPage = new Page<>(page, limit);
        Map<String, Object> map = teacherService.pageTeacherList(teacherPage);

        //返回分页的所有数据
        return R.ok().data(map);
    }

    /**
     * 根据讲师id查询教授课程
     * @param teacherId
     * @return
     */
    @GetMapping("/getCourseByTeacherId/{teacherId}")
    public R getCourseByTeacherId(@PathVariable String teacherId) {
        List<EduCourse> courseList = courseService.selectByTeacherId(teacherId);
        return R.ok().data("courseList", courseList);
    }
}
